//
//  WBTabBarViewController.swift
//  MyWeiBo
//
//  Created by mac on 15/3/4.
//  Copyright (c) 2015年 gpr. All rights reserved.
//

import UIKit

class WBTabBarViewController: UITabBarController {
        
    @IBOutlet weak var wbTabBar: WBTabBar!

    class func wbTabBarViewController() -> WBTabBarViewController {
       return UIStoryboard(name: "WBTabBarViewController", bundle: nil).instantiateInitialViewController() as! WBTabBarViewController
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setUpChildrenViewControllers()
    }
    
    func setUpChildrenViewControllers() {
        let homeVC = HomeViewController.homeNavigationControllerWithTitle("首页")
        setUpTabBarButtonWithImage(homeVC, imageName: "tabbar_home", selectedImageName: "tabbar_home_selected")
        
        let messageVC = MessageController.messageNavigationControllerWithTitle("消息")
        setUpTabBarButtonWithImage(messageVC, imageName: "tabbar_message_center", selectedImageName: "tabbar_message_center_selected")
        
        let discoverVC = DiscoverController.discoverNavigationControllerWithTitle("发现")
        setUpTabBarButtonWithImage(discoverVC, imageName: "tabbar_discover", selectedImageName: "tabbar_discover_selected")
        
        let profileVC = ProfileController.profileNavigationControllerWithTitle("我")
        setUpTabBarButtonWithImage(profileVC, imageName: "tabbar_profile", selectedImageName: "tabbar_profile_selected")
        
        // 发微博
        weak var weakSelf = self
        self.wbTabBar.composeButtonDidClickedClosure = {
            let composeVC = ComposeController.composeNavigationController()
            weakSelf?.presentViewController(composeVC, animated: true, completion: nil)
        }
    }
    
    func setUpTabBarButtonWithImage(childVC: UIViewController, imageName: String, selectedImageName: String) {
        childVC.tabBarItem.image = UIImage.originalImageWithName(imageName)
        childVC.tabBarItem.selectedImage = UIImage.originalImageWithName(selectedImageName)
        self.addChildViewController(childVC)
    }

    class func WBMaiViewController() -> UITabBarController {
        let storyboard = UIStoryboard(name: "WBTabBarViewController", bundle: nil)
        return storyboard.instantiateInitialViewController() as! UITabBarController
    }

}
